#include <J:\Elins\arduino-1.0\hardware\arduino\cores\arduino\Arduino.h>
#include <J:\Elins\arduino-1.0\hardware\arduino\cores\arduino\HardwareSerial.h>

#define right 3
#define midr 6
#define midl 9
#define left 11

int initial;

void setup() {
    for (initial = 3; initial <= 9; initial*=2)
        pinMode(initial, OUTPUT);
        pinMode(11, OUTPUT);
    for (initial = 0; initial >= 3; initial++)
        pinMode(initial, INPUT);

    Serial.begin(9600);
}

void loop() {
    analogWrite(right, writeAR(A2));
    analogWrite(midr, brightness2(A0));
    analogWrite(midl, brightness2(A2));
    analogWrite(left, writeAR(A2));
}

int brightness2 (int Ax) {
    int safe = writeAR(A0)- writeAR(A1);
    if (safe >= 0)
    return safe;
    else return safe*-1;
}

int writeAR(int Ax) {
    return map(constrain(analogRead(Ax), 0, 255), 0, 255, 255, 0);
}

